package cn.gjxblog.service;

import cn.gjxblog.utils.QiniuUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author gjx
 * @version v1.0
 * @Description 文件服务
 * @date 2018/12/7 15:18
 */
@Service
@Slf4j
public class FileService {
    /**
     *
     *
     * @param file  文件
     * @return  图片存储的相对路径
     */
    public String upload(byte[] data,String fileName){
        String newpath = null;
        newpath = QiniuUtil.upLoadImage(data,fileName);
        if(StringUtils.isEmpty(newpath)){
            log.error("上传文件失败");
            throw new RuntimeException("上传文件失败");
        }
        return newpath;
    }

}
